using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PerfectPaperPasswords;

public partial class CheckPasscode : System.Web.UI.Page
{
    private int maxColumn = Convert.ToInt32(ConfigurationManager.AppSettings["maxColumn"]);
    private int maxRow = Convert.ToInt32(ConfigurationManager.AppSettings["maxRow"]);
    private int maxPassList = Convert.ToInt32(ConfigurationManager.AppSettings["maxPassList"]);

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString.Count == 1)
        {
            SequenceKeyTextBox.Text = Request.QueryString[0];
        }
        if (!Page.IsPostBack)
        {
            Random random = new Random();
            LocationTextBox.Text = String.Format("{0}{1}",
                Char.ConvertFromUtf32(Char.ConvertToUtf32("A", 0) + random.Next(maxColumn)),
                random.Next(maxRow) + 1);
            PasscodeListTextBox.Text = String.Format("{0}", random.Next(maxPassList) + 1);
        }
    }
    protected void CheckPasscodeButton_Click(object sender, EventArgs e)
    {
        LocationTextBox.Text = LocationTextBox.Text.ToUpper();
        int passList = Convert.ToInt32(PasscodeListTextBox.Text) - 1;
        int column = Char.ConvertToUtf32(LocationTextBox.Text, 0) - Char.ConvertToUtf32("A", 0);
        int row = Convert.ToInt32(LocationTextBox.Text.Substring(1)) - 1;
        pppNet ppp = new pppNet(SequenceKeyTextBox.Text);
        ppp.PasscodeCount = maxColumn * maxRow;
        ResultLabel.Text = ppp.CheckPasscode(passList, column + row * maxColumn, PasscodeTextBox.Text) ? "Correct" : "Wrong";
        ResultLabel.CssClass = ResultLabel.Text;
        ResultLabel.Visible = true;
    }
}
